var request = require('request');
var iconv = require('iconv-lite');
request('http://192.168.1.1', function (error, response,body) {
  if (!error&&response.statusCode == 200) {
    //console.log(body) // 请求成功的处理逻辑

    var regExp=/document.getElementById\("Frm_Logintoken"\).value = "(.*)";/;
    var regExp1=/document.getElementById\("Frm_Loginchecktoken"\).value = (\d+);/;
    var res = regExp.exec(body);
    var res1 = regExp1.exec(body);
    //console.log(res[1]);
    //console.log(res1[1]);
    var hh="Frm_Logintoken=" +res[1] + "&Frm_Loginchecktoken=" + res1[1] + "&_cu_url=0&Right=2&Username=&UserRandomNum=95670920&Password=0b1c0803d1299bcc3f6d4bd997adef8c76a2f234f21fb9cb812d884f1568e88f&action=login";

    //console.log(hh);

///第三部分
    var request = require('request');
request({url:"http://192.168.1.1",
        method:"POST",
        headers:{
            'Cookie': '_TESTCOOKIESUPPORT=1'
        },
        body: hh

    },function (error, response,body) {
  if (!error&&response.statusCode == 200) {
    //console.log(response.headers['set-cookie'][0]) // 请求成功的处理逻辑
    var sid=response.headers['set-cookie'][0].split(';')[0];
    //console.log(sid);

    request({url:'http://192.168.1.1/getpage.gch?pid=1002&nextpage=user_sec_macfilter_conf_t.gch',
        method:'GET',
        headers:{'Cookie':sid}

}, function (error, response,body) {
    if (!error&&response.statusCode == 200) {
        var regExp5=/var session_token = "(\d+)";/g;
        //console.log(regExp5.exec(body)[1]);
        var token=regExp5.exec(body)[1];




        tokenn={"token":token};









        //console.log(body);
        console.log(tokenn);







    }



    })



  }});








  

  }
});

//console.log(shuchu);